package com.jq.aution.component;

import com.jq.aution.service.ProductInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * Created by jiangqi on 2020/10/20
 */
@Component
public class AutionTypeChangeTask {
    private Logger LOGGER= LoggerFactory.getLogger(AutionTypeChangeTask.class);

    @Autowired
    ProductInfoService productInfoService;

    @Qualifier("testThreadPool")
    @Autowired
    private ThreadPoolTaskExecutor executor;

    @Scheduled(cron = "0 0/1 * * * ?")
    private void changeAutionTypePdt(){
        executor.execute(()->{
                    LOGGER.info("定时器开始处理未开始拍卖");
                    Integer count1=productInfoService.changeAutionType("0");
                    LOGGER.info("定时器共处理"+count1+"个拍卖商品");
                }
        );
        executor.execute(()->{
                    LOGGER.info("定时器开始处理正在进行拍卖");
                    Integer count1=productInfoService.changeAutionType("1");
                    LOGGER.info("定时器共处理"+count1+"个拍卖商品");
                }
        );
    }
}
